﻿package mortal.game.view.tianDiRank.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.tianDiRank.data.*;
    import mortal.game.view.tianDiRank.item.*;
    import mortal.mvc.core.*;

    public class TianDiRankPassWin extends Window
    {
        protected var _bg:GImageBitmap;
        protected var _midBg:ScaleBitmap;
        protected var _titleBg:GImageBitmap;
        protected var _posAtt:GBitmap;
        protected var _posTitleL:GBitmap;
        protected var _posAttR:GBitmap;
        protected var _detailBtn:GButton;
        protected var _posList:CellsGridSprite;
        protected var _posName:GTextFiled;
        protected var _useTitleBtn:GLoadingButton;
        protected var _leaveBtn:GLoadingButton;
        protected var _buttomTip:GImageBitmap;
        protected var _resultIcon:GImageBitmap;
        protected var _posNoNum:BitmapNumberText;
        protected var _no:GBitmap;
        private var _isLoad:Boolean = false;
        private var _info:SPlacardChallengeResult;
        private var _reSult:int = 1;
        private var _titleDataInfo:TitleDataInfo;
        public static const totalTime:int = 120;
        private static var _instance:TianDiRankPassWin;

        public function TianDiRankPassWin()
        {
            this.setSize(625, 303);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.tianDiRank, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this._isLoad = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.ResultWinBg, 0, -57, this);
            this._midBg = UIFactory.bg(181, 82, 374, 119, this, ImagesConst.PanelBg);
            this._titleBg = UIFactory.gImageBitmap(ImagesConst.TianDiPassSuccTitleDes, 144, 40, this);
            this._posAtt = UIFactory.gBitmap(ImagesConst.TianDiRankPosAttr, 333, 87, this);
            this._posTitleL = UIFactory.gBitmap(ImagesConst.TitleLine, 240, 95, this);
            this._posAttR = UIFactory.gBitmap(ImagesConst.TitleLine, 504, 97, this);
            this._posAttR.scaleX = -1;
            this._detailBtn = UIFactory.gButton("" + Language.getString(71974), 549, 256, 110, 30, this, "GreenLinkButton");
            this._posList = UIFactory.getUICompoment(CellsGridSprite);
            this._posList.colNum = 2;
            this._posList.vCellWid = 120;
            this._posList.hCellWid = 25;
            this._posList.genCellFun = UIFactory.getUICompoment;
            this._posList.genCells(5, TianDiPosCell);
            this._posList.x = 262;
            this._posList.y = 113;
            this.addChild(this._posList);
            this._posName = UIFactory.gTextField("", 354, 47, 100, 25, this, GlobalStyle.textFormatZi.setSize(16).center().setBold(true));
            this._useTitleBtn = UIFactory.gLoadingButton(ImagesConst.TianDiPassUseTitleBtn_upSkin, 231, 252, 114, 34, this);
            this._useTitleBtn.label = "";
            this._leaveBtn = UIFactory.gLoadingButton(ImagesConst.leaveCopy2Btn_upSkin, 357, 252, 114, 34, this);
            this._leaveBtn.label = "";
            this._buttomTip = UIFactory.gImageBitmap(ImagesConst.TianDiPassSuccTip1, 183, 203, this);
            this._resultIcon = UIFactory.gImageBitmap(ImagesConst.ResultWinSuccess, 229, -43, this);
            this._posNoNum = UIFactory.bitmapNumberText(341, 47, "TianDiRankNum.png", 24, 25, -10, this, 10, 0);
            this._posNoNum.text = "3";
            this._no = UIFactory.gBitmap(ImagesConst.TianDiRankNo, 309, 47, this);
            this._leaveBtn.configEventListener(MouseEvent.CLICK, this.onLeaveCopyHd);
            this._detailBtn.configEventListener(MouseEvent.CLICK, this.onShowDetailHd);
            this._useTitleBtn.configEventListener(MouseEvent.CLICK, this.onUseTitle);
            this.updateAll();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._titleDataInfo = null;
            this._reSult = -1;
            this._isLoad = false;
            this._bg = null;
            this._midBg = null;
            this._titleBg = null;
            this._posAtt = null;
            this._posTitleL = null;
            this._posAttR = null;
            this._detailBtn = null;
            this._posList = null;
            this._posName = null;
            this._useTitleBtn = null;
            this._leaveBtn = null;
            this._buttomTip = null;
            this._resultIcon = null;
            this._posNoNum = null;
            this._no = null;
            LoaderHelp.removeResEvent(ResFileConst.tianDiRank, this.onResLoad);
            return;
        }// end function

        public function updateResult(param1:SPlacardChallengeResult) : void
        {
            if (param1 == null)
            {
                return;
            }
            this._info = param1;
            this.updateAll();
            return;
        }// end function

        private function updateAll() : void
        {
            if (this._info == null || this._isLoad == false)
            {
                return;
            }
            this.updateBg();
            this.updateTime();
            this.updatePos();
            this.updateTitle(this._titleDataInfo);
            return;
        }// end function

        private function updateBg() : void
        {
            if (this._info.result == 1)
            {
                this._posName.visible = true;
            }
            else
            {
                this._posName.visible = false;
            }
            if (this._reSult == this._info.result)
            {
                return;
            }
            this._reSult = this._info.result;
            return;
        }// end function

        private function updateTime() : void
        {
            var _loc_1:* = totalTime - this._info.time;
            return;
        }// end function

        private function updatePos() : void
        {
            var _loc_4:Object = null;
            var _loc_1:* = TianDiRankUtil.getRealIndex();
            var _loc_2:* = Cache.instance.tianDi.mainIdArr[_loc_1];
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2.indexOf(this._info.placardConfigId);
            if (_loc_3 != -1)
            {
                this._posNoNum.text = "" + TianDiRankUtil.getPosNum(_loc_3);
                _loc_4 = TianDiRankUtil.getCopyCfgByPos(_loc_3, true);
                this._posName.text = "" + _loc_4.jobName;
                this.updateAtt(_loc_4.titleId);
            }
            return;
        }// end function

        private function updateAtt(param1:int) : void
        {
            var _loc_4:TianDiPosCell = null;
            var _loc_5:Object = null;
            var _loc_2:* = TianDiRankUtil.getTitleAttr(param1);
            this._posList.genCells(_loc_2.length, TianDiPosCell);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = this._posList.cellArr[_loc_3];
                _loc_5 = _loc_2[_loc_3];
                _loc_4.updateInfo(_loc_5["attrName"], _loc_5["attrValue"]);
                _loc_3++;
            }
            return;
        }// end function

        private function onLeaveCopyHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankLeaveCopy));
            this.hide();
            return;
        }// end function

        private function onShowDetailHd(event:MouseEvent) : void
        {
            TianDiRankUtil.isCkShowPos = true;
            var _loc_2:* = Cache.instance.tianDi.isDiRankFlag;
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankPosAttListCk, _loc_2));
            return;
        }// end function

        private function onUseTitle(event:MouseEvent) : void
        {
            if (this._titleDataInfo == null)
            {
                this.hide();
                return;
            }
            this.hide();
            var _loc_2:* = Cache.instance.tianDi.isDiRankFlag;
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankUseTitle, this._titleDataInfo));
            this.onLeaveCopyHd(null);
            return;
        }// end function

        public function updateTitle(param1:TitleDataInfo) : void
        {
            this._titleDataInfo = param1;
            if (this._isLoad == false || this._titleDataInfo)
            {
                return;
            }
            return;
        }// end function

        private function onClosePanel(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            return;
        }// end function

        public static function get instance() : TianDiRankPassWin
        {
            if (_instance == null)
            {
                _instance = new TianDiRankPassWin;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
